<?php namespace Admin\Controller;
//类型控制器
class TypeController extends CommonController{
	private $model;
	//实例化model;
	public function __auto(){
		$this->model=new \Common\Model\Type;
	}
	//分类列表
	public function index(){
		$data=$this->model->get();
		View::with('data',$data);
//		p($data);
		View::make();
	}
	//添加分类
	public function add(){
		if(IS_POST){
			if($this->model->store()){
			View::success('添加成功',U('index'));
			}
		//提示相关错误信息
		View::error($this->model->getError());
		}
		View::make();
	}
	//编辑
	public function edit(){
		if(IS_POST){
			if($this->model->edit()){
				View::success('修改成功',U('index'));
			}
		View::error($this->model->getError());
			
		}
		//获取旧数据
		$tid=Q('get.tid',0,'intval');
		$oldData=$this->model->where("tid={$tid}")->find();
//		p($oldData);
		View::with('oldData',$oldData);
		View::make();
	}
	//删除
	public function del(){
		$tid=Q('get.tid',0,'intval');
		$this->model->where("tid='{$tid}'")->delete();
		View::success("删除成功");
	}
	
	
}

 ?>